﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.ComponentModel;
using System.Xml.Linq;

namespace Pavilion
{
    public class AnimationNode : NodeBase
    {
        public Animation Animation { get { return _animation; } set { SetAnimation(value); } }
        private Animation _animation;

        public AnimationNode(string name) : base() { base.Name = name; }
        public AnimationNode(Animation animation, string name): this(name) { this.Animation = animation; }

        public override void Dispose()
        {
            base.Dispose();
            Animation = null;
        }

        public override NodeBase Clone()
        {
            AnimationNode animationNode = new AnimationNode(Animation, Name);

            base.InsertParentContent(animationNode);

            return animationNode;
        }

        private void SetAnimation(Pavilion.Animation value)
        {
            if (_animation == value)
                return;

            if (_animation != null)
                _animation.Disposed -= new Action<Pavilion.Animation>(Animation_Disposed);

            _animation = value;

            if (_animation != null)
                _animation.Disposed += new Action<Pavilion.Animation>(Animation_Disposed);
        }

        private void Animation_Disposed(Animation animation)
        {
            Animation = null;
        }
    }
}
